package com.xiaohe.gulimall.product.web;

import com.xiaohe.gulimall.product.entity.CategoryEntity;
import com.xiaohe.gulimall.product.service.CategoryService;
import com.xiaohe.gulimall.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;
    @GetMapping({"/","index.html"})
    public String indexPage(Model model){
        //查询出所有的一级分类
        List<CategoryEntity> list = categoryService.getLevel1Category();
        model.addAttribute("categorys",list);
        return "index";
    }
    //in|dex/json/catalog.json
    @ResponseBody
    @GetMapping("/index/json/catalog.json")
    public Map<String, List<Catelog2Vo>>  getCatalogJson(){
        Map<String, List<Catelog2Vo>>  map =   categoryService.getCatalogJson();
        return map;
    }


}
